<template>
	<view>

	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {

		}
	}
</script>

<style>

</style>
<template>
	<button style="margin-top: 20%;" @click="openChat">进入聊天</button>
</template>
<script>
	import {
		TUILogin
	} from '@tencentcloud/tui-core';
	// #ifdef APP-PLUS || H5
	import {
		TUIChatKit
	} from '@/TUIKit';
	TUIChatKit.init();
	// #endif
	let vueVersion = 2;
	// #ifdef VUE3
	vueVersion = 3;
	// #endif

	const userInfo = uni.getStorageSync('USER_INFO') || ''
	if (userInfo) {
		uni.$SDKAppID = 1600104664; // Your SDKAppID userInfo.appId; 
		uni.$userID = 'testUser1'; // Your userID'testUser1' //userInfo.tencent_id
		// 'eJwtzMEKgkAUheF3mW0hd8Q7I0Ir3SSiiyysnTXjcJFSxqGM6N0zdXm*A-*HldnBe2rLIuZ7wLbzJqUfjhqa2enBHQdt*XoOqq37nhSLuADgEAgRLI8ee7J6ckT0AWBRR-e-SZRCSgj8tUJmahdZV-HChOaVwDsfU3ut8YJ1HFZle7rZ-YjnKt0kuYm7Hfv*ACByMs0_'
		uni.$userSig =
			'eJwtzMEKgkAUheF3mW0hd8Q7I0Ir3SSiiyysnTXjcJFSxqGM6N0zdXm*A-*HldnBe2rLIuZ7wLbzJqUfjhqa2enBHQdt*XoOqq37nhSLuADgEAgRLI8ee7J6ckT0AWBRR-e-SZRCSgj8tUJmahdZV-HChOaVwDsfU3ut8YJ1HFZle7rZ-YjnKt0kuYm7Hfv*ACByMs0_'; // Your userSig //userInfo.sig
	}

	export default {

		data() {
			return {
				"groupId": '',
			}
		},
		onShow() {
			if (userInfo) {
				console.log('---------chat----------', uni.$chat);
				if (!uni.$chat) {
					TUILogin.login({
						SDKAppID: uni.$SDKAppID,
						userID: uni.$userID,
						userSig: uni.$userSig,
						useUploadPlugin: true,
						framework: `vue${vueVersion}` // framework used vue2 / vue3
					}).then(() => {
						const {
							chat
						} = TUILogin.getContext();

						// 挂载到 Vue 原型
						uni.$chat = chat
						console.log('ccccccccccccccc', chat);
					}).catch(() => {});
				}
			} else {
				// 未登录，跳转到登录页面
				uni.reLaunch({
					url: "/pages/tabBar/login/login",
					success: () => {
						// #ifdef APP-PLUS
						plus.navigator.closeSplashscreen();
						// #endif
					}
				});
			}


			this.userInfo = uni.getStorageSync('USER_INFO') || ''
			// this.get_imgroup()
		},
		methods: {
			openChat() {
				// 1v1 chat: conversationID = `C2C${userID}`
				// group chat: conversationID = `GROUP${groupID}`
				// const groupId = '@TGS#3GTQV2VR5'
				this.groupId = '@TGS#3GTQV2VR5'
				const conversationID = `GROUP${this.groupId}`
				uni.navigateTo({
					url: `/TUIKit/components/TUIChat/index?conversationID=${conversationID}&groupId=${encodeURIComponent(this.groupId)}`
				});
			},
			async get_imgroup() {
				let res = await this.$api.get(global.apiUrls.post68c225ed71dcc, {
					courseplan_id: 77,
					baseclass_id: this.userInfo.baseclass_id
				})
				console.log('00000000000000000', res.data.data)

				if (res.data.code == 1) {
					//  '@TGS#3GTQV2VR5'
					this.groupId = res.data.data.imgroup_groupid

					uni.setStorageSync('BASEOBJ', res.data.data);
				}
			},
		}
	}
</script>